package com.hw.controller;

import com.hw.entity.dto.sys.UserInfoDTO;
import com.hw.entity.vo.sys.UserInfoVO;
import com.hw.entity.vo.sys.UserSimpleInfoVO;
import com.hw.model.ResponseResult;
import com.hw.service.sys.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户
 *
 * @author whw
 * @date 2021/6/22
 */
@Api(tags = "用户")
@RestController()
@RequestMapping("/user")
public class SysUserController {
    @Autowired
    SysUserService sysUserService;

    @ApiOperation(value = "获取用户信息")
    @GetMapping("/getInfo")
    public ResponseResult<UserInfoVO> getInfo() {
        return ResponseResult.success(sysUserService.getInfo());
    }

    @ApiOperation(value = "获取用户简单信息")
    @GetMapping("/getSimpleInfo")
    public ResponseResult<UserSimpleInfoVO> getSimpleInfo() {
        return ResponseResult.success(sysUserService.getSimpleInfo());
    }

    @ApiOperation(value = "保存头像")
    @PostMapping("/saveAvatar")
    public ResponseResult<?> saveAvatar(@RequestParam(value = "file") MultipartFile file) {
        sysUserService.updateAvatar(file);
        return ResponseResult.success();
    }

    @ApiOperation(value = "保存信息")
    @PostMapping("/save")
    public ResponseResult<?> save(@RequestBody UserInfoDTO dto) {
        sysUserService.save(dto);
        return ResponseResult.success();
    }


}
